<?php
/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2018/3/8
 * Time: 下午5:12
 */

namespace backend\controllers;

use backend\models\UserSearch;
use common\models\User;
use yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;

class UserController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'allow' => true,
                        'roles' => ['@'],
                    ]
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    public function actionIndex()
    {
        $model = new UserSearch();
        $dataProvider = $model->search(Yii::$app->request->get());
        return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]);
    }

    public function actionDelete($id)
    {
        $model = User::findOne($id);
        if ($model->delete()) {
            return $this->redirect(['index']);
        }
    }
}
